import {Component} from 'react'
import './../pages/index.css'
import './conent.css'
import Newmianbao from "./newmianbao";
import {inject,observer} from "mobx-react";
import {withRouter} from 'react-router-dom'
import Nav from "./nav";
@inject('login')
@observer
class Content extends Component{
    constructor(props) {
        super(props);
        this.state={username:'',isLogin:'',password:''}
        this.tuichu =this.tuichu.bind(this)
    }
    componentWillMount() {
        this.setState({
            username:this.props.login.user
        })
        const countStatus = this.props.login.isLogin;
       if (countStatus===true){
           this.props.history.push('/index')
       }else {
           this.props.history.push('/')
       }
    }
    tuichu(){
        this.state.username=''
        this.state.password =''
        this.props.login.upLogin(this.state.username,this.state.password)
        this.props.history.push('/')
    }
    render() {
        return (
            <div className='index'>
                <div className='left'><Nav/></div>
                <div className='right'>
                    <header className='toubu' history={this.props.history}>
                        <div className='logo'></div>
                        <p className='usernicheng'>{this.state.username}</p>
                        <button className='tui' onClick={this.tuichu} ref={this.annui}>退出</button>
                    </header>
                    <div className='mianbao'>
                        <Newmianbao/>
                    </div>
                    <main className='neirong'>
                        {this.props.children}
                    </main>
                </div>
            </div>
        )
    }
}

export default withRouter (Content)